package eval.vm;

import java.io.Serializable;

/**
 * Encapsulates an identifier for a virtual machine.
 * Immutable object
 * 
 * @author Amit Peled   <amit.kapina@gmail.com>
 * @author Igal Kaufman <igal.kaufman@gmail.com>
 * */
public class VMIdentifier implements Serializable {

	private static final long serialVersionUID = 1L;

	private final int vmIdentifier;

	/**
	 * @Constructor
	 * @param identifier VM id
	 */
	VMIdentifier(int identifier) {
		this.vmIdentifier = identifier;
	}

	/**
	 * Unique identifier for the VM.
	 * 
	 * @return VM id
	 */
	public int getID() {
		return vmIdentifier;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + vmIdentifier;
		return result;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		VMIdentifier other = (VMIdentifier) obj;
		if (vmIdentifier != other.vmIdentifier)
			return false;
		return true;
	}

	/* (non-Javadoc)
	 * @see java.lang.Object#toString()
	 */
	@Override
	public String toString() {
		return "ID: " + vmIdentifier;
	}

}